package com.wmwu.mybatistest.condition;

import com.wmwu.mybatistest.annotations.DataCoverageDataAuth;
import org.springframework.stereotype.Component;

import static com.wmwu.mybatistest.constants.BaseConstants.WHERE;

/**
 * @Description: 管理员/本人查看条件
 * @author: Mr.wu
 * @date: 2022年06月23日 17:53
 */
@Component("dataAuthAdminWithUserCondition")
public class DataAuthAdminWithUserCondition implements DataAuthCondition {

    @Override
    public String resetSql(DataCoverageDataAuth dataAuth, String oriSql) {
        String fieldName = dataAuth.column();
        //当前用户信息x
        String x = "人民币1";
        String resetSql = null;
        switch (dataAuth.type()) {
            case I:
                if (oriSql.toLowerCase().contains(WHERE)) {
                    resetSql = oriSql.replaceFirst("\\?", "? and " + fieldName + " = '" + x + "'");
                }
                break;
            case II:
                System.out.println("条件不存在!!!");
                break;
            default:
                break;
        }
        return resetSql;
    }
}
